package com.example.beat_x3.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.beat_x3.R;

import java.util.ArrayList;

import Entity.Inf;

public class SendersAdapter extends RecyclerView.Adapter<SendersAdapter.Holder>{
    public ArrayList<String> senders;
    private OnItemClickListener mOnItemClickListener;
    public interface OnItemClickListener {
        void onItemClick(String studentAccount);
    }
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    @NonNull
    @Override
    public SendersAdapter.Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SendersAdapter.Holder(LayoutInflater.from(Inf.context).inflate(R.layout.layout_sender, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull SendersAdapter.Holder holder, int position) {
        holder.bind(position);
    }

    @Override
    public int getItemCount() {
        if(senders==null)return 0;
        return senders.size();
    }
    class Holder extends RecyclerView.ViewHolder {
        TextView sender;
        String studentAccount;
        public Holder(@NonNull View itemView) {
            super(itemView);
            sender=itemView.findViewById(R.id.senders);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mOnItemClickListener != null) {
                        mOnItemClickListener.onItemClick(studentAccount);
                    }
                }
            });
        }
        void bind(int position){
            studentAccount=senders.get(position);
            sender.setText(studentAccount);
        }
    }
}
